<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>订单列表页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta name="csrf-token" content="{{csrf_token()}}">
    @include('home.public.style')
    @include('home.public.script')
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>商品id</th>
                            <th>商品名称</th>
                            <th>商品价格</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($goods as $v)
                            <tr>
                                <td>{{$v->id}}</td>
                                <td>{{$v->name}}</td>
                                <td>{{$v->price}}</td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        var form = layui.form;


        // 监听全选
        form.on('checkbox(checkall)', function (data) {

            if (data.elem.checked) {
                $('tbody input').prop('checked', true);
            } else {
                $('tbody input').prop('checked', false);
            }
            form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
            ,type: 'datetime'
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
            ,type: 'datetime'
        });

    });

    /*用户-停用*/
    function member_stop(obj, id) {
        status = '推送失败';
        layer.confirm('确认要' + status + '吗？', function (index) {

            $.get("/home/branch/orderError",{'id':id},function(){
                layer.msg('已推送失败!', {icon: 5, time: 400}, function (data) {
                    // 可以对当前口进行刷新
                    location.reload();
                });
            })

        });
    }

    /*用户-启用*/
    function member_start(obj, id) {
        status = '推送成功';
        layer.confirm('确认要' + status + '吗？', function (index) {

            $.get("/home/branch/orderSuccess",{'id':id},function(){
                layer.msg('已推送成功!', {icon: 5, time: 400}, function (data) {
                    // 可以对当前口进行刷新
                    location.reload();
                });
            })

        });
    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                method: 'delete',
                url: "/home/order/" + id,
                dateType: 'json',
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
                },
                success: function (data) {
                    layer.msg("删除成功", {
                            icon: 1,
                            time: 400 //2秒关闭（如果不配置，默认是3秒）
                        },
                        function () {
                            // 可以对当前口进行刷新
                            location.reload();
                        });
                },
            })
        });
    }


    function delAll(argument) {
        var ids = [];
        // 获取选中的id
        $('tbody input').each(function (index, el) {
            if ($(this).prop('checked')) {
                ids.push($(this).val())
            }
        });
        layer.confirm("确认要删除吗?", function () {
            $.ajax({
                type: 'post',
                url: "/home/order/delAll",
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')
                },
                data: {ids: ids},
                success: function (data) {
                    layer.msg("删除成功", {
                        icon: 1,
                        time: 400 //2秒关闭（如果不配置，默认是3秒）
                    },
                    function () {
                        // 可以对当前口进行刷新
                        location.reload();
                    });
                },
            })
        });
    }

    function fresh_page(){
        window.location.reload();
    }

    setInterval('fresh_page()',30000);
</script>
</html>